import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService, BeActionService } from '@farris/command-services';
import { EMPTY, of } from 'rxjs';
import { tap, map, switchMap } from 'rxjs/operators';

@Injectable()
export class GyjbfsqformFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private messageService: FormMessageService,
    private beActionService: BeActionService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) { }

  /**
   * 新增数据
   * @remarks 
   * @returns 
   */
  addData(): any {
    const context = this.frameContext;
    let id = context.bindingData.getValue(['id'])
    const rep = this.frameContext.repository as BefRepository<any>;
    const datas = this.frameContext.uiState['datas'];
    let tzDadas = []
    debugger
    for (let item of datas) {
      const tzid = item.data.id
      const debh = item.data.debh
      const gyjmc = item.data.gyjmc
      const ggxh = item.data.ggxh
      const lxmc = item.data.lx.lxmc
      // const lx = item.data.lx.lx
      tzDadas.push({
        gyjtzid: {
          gyjtzid: tzid,
          gyjtzid_debh: debh,
          gyjtzid_gyjmc: gyjmc,
          gyjtzid_lx: {
            // lx: lx,
            lx_lxmc: lxmc
          },
          gyjtzid_ggxh: ggxh
        }
      })
    }
    // gzlxsqmx
    rep.batchAppendByPath('/' + id + '/bfmxs', tzDadas).subscribe()
  }
}
